/**
 * 功能描述
 * 服务器交互
 */

define(function (require, exports, module) {
    var aw = require("ajaxwrapper");
    var store = require("store");
	
    module.exports = {
    	queryMemberByCard:function(cardId,callback){

            aw.ajax({
                url :"api/cardmanagement/query",
                data : {
                    chipNumber:cardId,
                    fetchProperties:"chipNumber,cardNumber"
                },
                success : function(data){
                    $("#cardNumber").val(data[0].cardNumber);
                }
            });

            var url =  window.location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for(var i = 0; i < strs.length; i ++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }

    		aw.ajax({
				url :"api/cate/account/querycustomerinfobycard",
				data : {
					//"roomPersonalInfo.consumeCard.cardNumber":cardId,   加入员工的情况
					"token" : theRequest["token"],
					"cardId" : cardId,
                    "fetchProperties":"*,member.personalInfo.name,member.organization.pkOrganization"
				},
				success : function(data){
					callback(data);
				}
			});
    	},
    	queryMemberById:function(idNum,callback){
            var url =  window.location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for(var i = 0; i < strs.length; i ++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
    		aw.ajax({
				url :"api/member/query",
				data : {
					"token" : theRequest["token"],
					"personalInfo.idNumber":idNum,
					//"organization.pkOrganization":store.get("user").organization.pkOrganization,
					"fetchProperties":"*,personalInfo.name",
					validatePrivilege:false,
				},
				success : function(data){
					callback(data);
				}
			});
    	},
    	createPreOrder:function(cartData,callback,errorCallBack){
            var url =  window.location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for(var i = 0; i < strs.length; i ++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            cartData.token=theRequest["token"];
    		aw.ajax({
				url :"api/cate/account/paybedbycard",
				type : "POST",
				data : aw.customParam(cartData),
				success : function(data){
					callback(data);
				},
				error : function(data){
					errorCallBack(data);
				}
			});
    	},
    	userMe:function(){
    		aw.ajax({
				url :"api/user/me",
				data : {
					
				},
				success : function(data){
					
				}
			});
    	}
    };
});
